package be.ac.ua.pats.thesisrobotica.robot.sensors;

//~--- non-JDK imports --------------------------------------------------------

import be.ac.ua.pats.thesisrobotica.robot.communication.Connection;

/**
 * @author Jimmy
 */
public abstract class Sensor {
    protected int        interval  = 0;
    protected int        threshold = 0;
    protected Connection connection;
    protected String     id;
    protected String     type;

    public Sensor() {
        this.id = IdFactory.generate();
    }

    public Sensor(Connection connection) {
        this.connection = connection;
        this.id         = IdFactory.generate();
    }

    public abstract String getValue();

    public abstract void setValue(String s);

    public String getType() {
        return type;
    }

    public String getId() {
        return id;
    }

    public int getThreshold() {
        return threshold;
    }

    public int getInterval() {
        return interval;
    }

    public void setConnection(Connection connection) {
        this.connection = connection;
    }

    public void setTimeInterval(int interval) throws IllegalArgumentException {
        if (interval < 0) {
            throw new IllegalArgumentException("Illegal time interval:" + interval);
        }

        this.interval = interval;
    }

    public void setThreshold(int threshold) throws IllegalArgumentException {
        if (threshold < 0) {
            throw new IllegalArgumentException("Illegal threshold:" + threshold);
        }

        this.threshold = threshold;
    }
}
